#!/usr/bin/perl

# $Id: 04_ftplisting_unix.t 144 2010-06-26 14:48:25Z dolbanavt $
# $Date: 2010-06-26 17:48:30 +0300 (Суб, 26 Июн 2010) $
# $HeadURL: https://robosearch.googlecode.com/svn/branches/reborn/t/04_ftplisting_unix.t $
# $LastChangedRevision$

use FindBin qw( $RealBin );
use File::Spec::Functions qw( catfile );

BEGIN {
    push @INC, catfile( $RealBin, '..', 'base_lib' );
    push @INC, catfile( $RealBin, '..', 'lib' );
}

use JIP::ToolSet;
use English qw( -no_match_vars );
use Test::More tests => 16;
use Const::Fast qw( const );

const my $MODULE => 'FTPListing::Unix';

use_ok $MODULE;
require_ok $MODULE;

can_ok $MODULE, qw( new parse_listing_for );

my $parser = $MODULE->new();

ok $parser, 'got object';

isa_ok $parser, $MODULE;
isa_ok $parser, 'FTPListing';
isa_ok $parser, 'JIP::BaseClass';

{
    my @l = $parser->parse_listing_for(
        '-rwxr-xr-x 1  ftp ftp 128 Feb 15 17:34 filename'
    );

    is scalar @l, 1, 'got single record';

    is $l[0]->{'name'}, 'filename', 'parse_listing_for(file) - record name';
    is $l[0]->{'type'}, 'f',        'parse_listing_for(file) - record type';
    is $l[0]->{'size'}, '128',      'parse_listing_for(file) - record size';
}

{
    my @l = $parser->parse_listing_for(
        'drwxr-xr-x 1  ftp ftp 0 Feb 15 17:34 dirname'
    );

    is $l[0]->{'name'}, 'dirname', 'parse_listing_for(dir) - record name';
    is $l[0]->{'type'}, 'd',       'parse_listing_for(dir) - record type';
    is $l[0]->{'size'}, undef,     'parse_listing_for(dir) - record size';
}

{
    my @l = $parser->parse_listing_for(
        'drwxr-xr-x 1  ftp ftp 0 Feb 15 17:34 .'
    );

    is $l[0], undef, 'parse_listing_for(dir) - empty record for .';
}

{
    my @l = $parser->parse_listing_for(
        'drwxr-xr-x 1  ftp ftp 0 Feb 15 17:34 ..'
    );

    is $l[0], undef, 'parse_listing_for(dir) - empty record for ..';
}
